package com.yjxxt.gradeLevel;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 视频单元考核   作业单元考核  考试单元考核  总成绩     性别
 *    20	       47.2	      30	   97.2	     女
 */

public class StudentMapper extends Mapper<LongWritable , Text , Text , DoubleWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, DoubleWritable>.Context context) throws IOException, InterruptedException {
        //拆分数据
        String [] person = value.toString().split("\t");
        // 判断是否为脏数据
        if(person != null && person.length==5){

            // 将性别拆分提取
            String gender=person[4];

            // 将总成绩拆分提取，存储为double类型
            double grade = Double.parseDouble(person[3]);

            // 将性别gender作为输出的key ， 将总成绩grade作为key对应的value
            context.write(new Text(gender),new DoubleWritable(grade));

        }
    }
}
